import request from "@/utils/request";
import type { AxiosPromise } from "axios";
import type {
  PlayHistoryVO,
  PlayHistoryForm,
  PlayHistoryQuery,
} from "@/api/playHistory/types";

/**
 * 查询统一播放记录列表
 * @param query
 * @returns {*}
 */

export const listPlayHistory = (
  query?: PlayHistoryQuery
): AxiosPromise<PlayHistoryVO[]> => {
  return request({
    url: "/business/playHistory/list",
    method: "get",
    params: query,
  });
};

/**
 * 查询统一播放记录详细
 * @param id
 */
export const getPlayHistory = (
  id: string | number
): AxiosPromise<PlayHistoryVO> => {
  return request({
    url: "/business/playHistory/" + id,
    method: "get",
  });
};

/**
 * 通过内容id获取统一播放记录详细信息
 * @param contentId 内容id
 * @param contentType 内容类型：1-视频，2-音频
 */
export const getPlayHistoryWithIdType = (
  contentId: string | number,
  contentType: number
): AxiosPromise<PlayHistoryVO> => {
  return request({
    url: "/business/playHistory/" + contentId + "/" + contentType,
    method: "get",
  });
};

/**
 * 新增统一播放记录
 * @param data
 */
export const addPlayHistory = (data: PlayHistoryForm) => {
  return request({
    url: "/business/playHistory",
    method: "post",
    data: data,
  });
};

/**
 * 修改统一播放记录
 * @param data
 */
export const updatePlayHistory = (data: PlayHistoryForm) => {
  return request({
    url: "/business/playHistory",
    method: "put",
    data: data,
  });
};

/**
 * 删除统一播放记录
 * @param id
 */
export const delPlayHistory = (
  id: string | number | Array<string | number>
) => {
  return request({
    url: "/business/playHistory/" + id,
    method: "delete",
  });
};
